package algorithm.graph;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

/**
 * @Description 读取图的信息
 * @author bingo
 * @Date 2018/3/13
 */
public class ReadGraph {

    private Scanner scanner;


    public Graph readGraph(Graph graph,String fileName){
        readFile(fileName);
        int n  = scanner.nextInt();

        int m = scanner.nextInt();

        for(int i=0;i<m;i++){
            int v = scanner.nextInt();
            int w = scanner.nextInt();
            graph.addEdge(v,w);
        }
          return  graph;
        }

    public void readFile(String fileName){

        File file = new File(fileName);

        try {
            FileInputStream fis = new FileInputStream(file);
            scanner = new Scanner(new BufferedInputStream(fis),"utf-8");
            } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {

        String fileName = "demo/component1.txt";
        ReadGraph readGraph = new ReadGraph();
        /**@Description 稀疏图:邻接表**/
        Graph sparseGraph = new SparseGraph(13, false);
        sparseGraph = readGraph.readGraph(sparseGraph, fileName);
        sparseGraph.show();

         Graph denseGraph = new DenseGraph(13,false);
         denseGraph = readGraph.readGraph(denseGraph,fileName);
         denseGraph.show();

    }


}
